#include <sxCuboid.h>

const static float DEFAULT_MIN = -0.5f;
const static float DEFAULT_MAX = 0.5f;

Sx::Graphics::Objects::Cuboid::Cuboid() {
	this->min.x() = this->min.y() = this->min.z() = DEFAULT_MIN;
	this->max.x() = this->max.y() = this->max.z() = DEFAULT_MAX;
}

Sx::Graphics::Objects::Cuboid::Cuboid(const Eigen::Vector3f& min, const Eigen::Vector3f& max) {
	this->min = min;
	this->max = max;
}

Sx::Graphics::Objects::Cuboid::Cuboid(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
	this->min.x() = minX;
	this->min.y() = minY;
	this->min.z() = minZ;
	this->max.x() = maxX;
	this->max.y() = maxY;
	this->max.z() = maxZ;
}

Sx::Graphics::Objects::Cuboid::~Cuboid() {}

bool Sx::Graphics::Objects::Cuboid::construct() { return true; }
void Sx::Graphics::Objects::Cuboid::update(float dt) { return; }

void Sx::Graphics::Objects::Cuboid::setMin(const Eigen::Vector3f& min) {
	this->min = min;
}

void Sx::Graphics::Objects::Cuboid::setMin(float x, float y, float z) {
	this->min.x() = x;
	this->min.y() = y;
	this->min.z() = z;
}

void Sx::Graphics::Objects::Cuboid::setMax(const Eigen::Vector3f& max) {
	this->max = max;
}

void Sx::Graphics::Objects::Cuboid::setMax(float x, float y, float z) {
	this->max.x() = x;
	this->max.y() = y;
	this->max.z() = z;
}

Eigen::Vector3f Sx::Graphics::Objects::Cuboid::getCorner(bool x, bool y, bool z) {
	float px = this->max.x();
	float py = this->max.y();
	float pz = this->max.z();
	float nx = this->min.x();
	float ny = this->min.y();
	float nz = this->min.z();

	// 000
	// 001
	// 010
	// 011
	// 100
	// 101
	// 110
	// 111

	if ( !x && !y && !z ) return Eigen::Vector3f(nx, ny, nz);
	if ( !x && !y && z ) return Eigen::Vector3f(nx, ny, pz);
	if ( !x && y && !z ) return Eigen::Vector3f(nx, py, nz);
	if ( !x && y && z ) return Eigen::Vector3f(nx, py, pz);
	if ( x && !y && !z ) return Eigen::Vector3f(px, ny, nz);
	if ( x && !y && z ) return Eigen::Vector3f(px, ny, pz);
	if ( x && y && !z ) return Eigen::Vector3f(px, py, nz);
	if ( x && y && z ) return Eigen::Vector3f(px, py, pz);
	return Eigen::Vector3f::Zero();
}

Eigen::Vector3f Sx::Graphics::Objects::Cuboid::getMin() const {
	return this->min;
}

Eigen::Vector3f Sx::Graphics::Objects::Cuboid::getMax() const {
	return this->max;
}

float Sx::Graphics::Objects::Cuboid::getMinX() const {
	return this->min.x();
}

float Sx::Graphics::Objects::Cuboid::getMinY() const {
	return this->min.y();
}

float Sx::Graphics::Objects::Cuboid::getMinZ() const {
	return this->min.z();
}

float Sx::Graphics::Objects::Cuboid::getMaxX() const {
	return this->max.x();
}

float Sx::Graphics::Objects::Cuboid::getMaxY() const {
	return this->max.y();
}

float Sx::Graphics::Objects::Cuboid::getMaxZ() const {
	return this->max.z();
}
